package com.jinxin.platform.cdinfogo.controller;

import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cdinfogo.pojo.domain.CdinfogoLedProgram;
import com.jinxin.platform.cdinfogo.rpc.CdInfoGoRpcService;
import com.jinxin.platform.cdinfogo.service.IZsLedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-11-22
 * @Author: Lingnan
 **/
@Api(tags = "led接口")
@RestController
@RequestMapping("cdinfogoLed")
public class ZsLedController {
    @Autowired
    private IZsLedService zsLedService;
    @Autowired
    private CdInfoGoRpcService cdInfoGoRpcService;

    @ApiOperation(value = "新增或更新(多个)节目")
    @PostMapping("/saveOrUpdateProgram")
    public JsonResult saveOrUpdateProgram(@RequestBody List<CdinfogoLedProgram> programList){
        return zsLedService.saveOrUpdateProgram(programList);
    }

    @ApiOperation(value = "根据mac查询节目列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mac",value="led设备mac",required=true,paramType="query",dataType="String")
    })
    @GetMapping("/queryProgramByMac")
    public JsonResult queryProgramByMac(String mac){
        return zsLedService.queryProgramByMac(mac);
    }

    @ApiOperation(value = "播放节目")
    @PostMapping("/sendToScreen")
    public JsonResult sendToScreen(@RequestBody CdinfogoLedProgram program){
        return zsLedService.sendToScreen(program);
    }

    @ApiOperation(value = "生成模式")
    @PostMapping("/saveAsMode")
    public JsonResult saveAsMode(@RequestBody CdinfogoLedProgram program){
        return zsLedService.saveAsMode(program);
    }

    @ApiOperation(value = "删除模式")
    @PostMapping("/deleteMode")
    public JsonResult deleteMode(@RequestBody CdinfogoLedProgram program){
        String account = program.getAccount();
        String ymsid = program.getYmsid();
        String modeId = program.getModeId();
        String programId = program.getId();
        String mac = program.getMac();
        if(StringUtils.isEmpty(account) || StringUtils.isEmpty(ymsid) || StringUtils.isEmpty(modeId) ||
                StringUtils.isEmpty(programId) || StringUtils.isEmpty(mac)){
            return JsonResult.error("参数错误");
        }
        return cdInfoGoRpcService.deleteMode(account,ymsid,modeId,programId,mac);
    }

    @ApiOperation(value = "根据mac查询屏大小")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mac",value="led设备mac",required=true,paramType="query",dataType="String")
    })
    @GetMapping("/queryWidthHeightByMac")
    public JsonResult queryWidthHeightByMac(String mac){
        return cdInfoGoRpcService.getBoardParam("",mac);
    }

    @ApiOperation(value = "根据Id删除节目")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="节目ID",required=true,paramType="query",dataType="String")
    })
    @GetMapping("/removeProgramById")
    public JsonResult removeProgramById(String id){
        return zsLedService.removeProgramById(id);
    }

    @ApiOperation(value = "根据Id删除组件")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="组件ID",required=true,paramType="query",dataType="String")
    })
    @GetMapping("/removeModuleById")
    public JsonResult removeModuleById(String id){
        return zsLedService.removeModuleById(id);
    }


}
